home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / ZICSLST.CPP < prev    next >
C/C++ Source or Header  |  1993-08-09  |  8KB  |  274 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    zicslst.cpp
  5. //   Title:    9 Digit ZIP Disc Interface
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains code for the class ZI_CS_LIST.
  24. //
  25. //    The code in this module may be written in C++ or C.
  26. //
  27. //    This module is portable to:
  28. //        DOS 3.X+
  29. //        MS Windows 3.X+
  30. //        OS/2 2.X+
  31. //        OS/2 2.0 PM
  32. //
  33. //    The following compilers are supported:
  34. //        MSC 6.0A
  35. //        MSC/C++ 7.0
  36. //        Borland C++ 3.1 for DOS
  37. //        Borland C++ 1.0 for OS/2 2.X
  38. //
  39. //----------------------------------------------------------------------------
  40. #include <zi.hpp>
  41. #define USE_WIN_CS_LIST
  42. #if OS_DOS
  43. #include <zid.hpp>
  44. #elif OS_WINDOWS
  45. #include <ziw.hpp>
  46. #else
  47. #include <zio.hpp>
  48. #endif
  49.  
  50.  
  51. //----------------------------------------------------------------------------
  52. //   Description:    Default constructor
  53. //    Parameters:
  54. //       Returns:    
  55. //----------------------------------------------------------------------------
  56. FN_M ZI_CS_LIST::ZI_CS_LIST(SIZET cRecs, PRECID _precid, PCSZ _pcszZip5)
  57. : ZN_WINDOW("WIN_CS_LIST", ZN_LOAD_CENTER|ZN_LOAD_HELPBAR|ZN_LOAD_NO_SHOW)
  58. {
  59.     ZI_CS_LIST::Initialize(CL_INIT_CLASS);
  60.     Assert(_precid);
  61.     precid = _precid;
  62.     lRecords = (LONG)cRecs;
  63.     pcszZip5 = _pcszZip5;
  64.     Setup();
  65. }
  66.  
  67.  
  68. //----------------------------------------------------------------------------
  69. //   Description:    Destructor
  70. //    Parameters:
  71. //       Returns:    
  72. //----------------------------------------------------------------------------
  73. FN_M ZI_CS_LIST::~ZI_CS_LIST()
  74. {
  75.     ZI_CS_LIST::Destroy(FALSE);
  76.     Terminate();
  77. }
  78.  
  79.  
  80. //----------------------------------------------------------------------------
  81. //   Description:    Destroy object. Free any resources used by object.
  82. //                          Normally called by destructor.
  83. //                        Should allow multiple calls from various classes.
  84. //                        A class should almost always re-init its variables when 
  85. //                        it is destroyed to prevent accidents.
  86. //    Parameters:    fDestroyAll        Destroy parents also?
  87. //                                            Default is TRUE.
  88. //       Returns:    TRUE if successful.
  89. //----------------------------------------------------------------------------
  90. BOOL FN_M ZI_CS_LIST::Destroy(BOOL fDestroyAll)
  91. {
  92.     ZI_CS_LIST::Initialize(CL_INIT_CLASS_VARS);
  93.     if (fDestroyAll)                            // Destroy parent.
  94.         ZI_CS_LIST_PARENT::Destroy(fDestroyAll);
  95.     return TRUE;
  96. }
  97.  
  98.  
  99. //----------------------------------------------------------------------------
  100. //   Description:    Display detail windows
  101. //    Parameters:
  102. //       Returns:    TRUE if successful.
  103. //----------------------------------------------------------------------------
  104. BOOL FN_M ZI_CS_LIST::Detail()
  105. {
  106.     if (!Z4_INQ::cs_file.Record(Z4_INQ::cs, precid[(SIZET)lCurrent]))
  107.         return FALSE;
  108.  
  109.     PZI_CS_DETAIL pzi_cs_detail = new ZI_CS_DETAIL(Z4_INQ::cs);
  110.     if (pzi_cs_detail == NULL)
  111.         return ErrorNoMem();
  112.     else if (pzi_cs_detail->IsValid())
  113.         pzi_cs_detail->Show();
  114.     return TRUE;
  115. }
  116.  
  117.  
  118. //----------------------------------------------------------------------------
  119. //   Description:    Initialize object. 
  120. //                          Normally called by constructor.
  121. //                        Should allow multiple calls from various classes.
  122. //    Parameters:    sInit        Initialization code. May be one of the following:
  123. //                                        CL_INIT_CLASS            Reset class variables and
  124. //                                                                    and dynamic allocations for
  125. //                                                                    this class only.
  126. //                                        CL_INIT_CLASS_VARS    Reset class variables for
  127. //                                                                    this class only.
  128. //                                        CL_INIT_VARS            Reset class variables for
  129. //                                                                    this class only.
  130. //                                        CL_INIT_ALL                Initialize class and all 
  131. //                                                                    parent class, including
  132. //                                                                    dynamic memory allocation.
  133. //                                    Default is CL_INIT_ALL
  134. //       Returns:    TRUE if successful.
  135. //----------------------------------------------------------------------------
  136. BOOL FN_M ZI_CS_LIST::Initialize(SHORT sInit)
  137. {
  138.     if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
  139.         ZI_CS_LIST_PARENT::Initialize(sInit);
  140.  
  141.     lCurrent = 0;
  142.     lRecords = 0;
  143.     precid = NULL;
  144.     pcszZip5 = NULL;
  145.     return TRUE;
  146. }
  147.  
  148.  
  149. //----------------------------------------------------------------------------
  150. //   Description:    Set field values.
  151. //    Parameters:
  152. //       Returns:    TRUE if valid
  153. //----------------------------------------------------------------------------
  154. BOOL FN_M ZI_CS_LIST::Query(PZN_VLIST_ELEM pzn_vlist_elem)
  155. {
  156.     pzn_vlist_elem->pszBuf = szFormat;
  157.     szFormat[0] = '\0';
  158.     if (!Z4_INQ::cs_file.Record(Z4_INQ::cs, precid[(SIZET)pzn_vlist_elem->lId]))
  159.         return FALSE;
  160.  
  161.     sprintf(szFormat, "\t%s\t%s\t%s",
  162.         Z4_ST_FILE::Abbreviation(Z4_INQ::cs.state), Z4_INQ::cs.szCity, pcszZip5);
  163.  
  164.     return TRUE;
  165. }
  166.  
  167.  
  168. //----------------------------------------------------------------------------
  169. //   Description:    Set field values.
  170. //    Parameters:
  171. //       Returns:    TRUE if valid
  172. //----------------------------------------------------------------------------
  173. BOOL FN_M ZI_CS_LIST::Select()
  174. {
  175.     if (!Z4_INQ::cs_file.Record(Z4_INQ::cs, lCurrent))
  176.         return FALSE;
  177.  
  178.     SendMessage(ZiMainWindow(), ZI_MSG_STATE, NULL,    (PVOID)Z4_ST_FILE::Abbreviation(Z4_INQ::cs.state));
  179.     PCSZ pcszCity = (Z4_INQ::cs.facility == Z4_FACILITY_OTHER ? Z4_INQ::cs.szLastLineName: Z4_INQ::cs.szCity);
  180.     SendMessage(ZiMainWindow(), ZI_MSG_CITY, NULL, (PVOID)pcszCity);
  181.     SendMessage(ZiMainWindow(), ZI_MSG_ZIP5, NULL, (PVOID)pcszZip5);
  182.     return TRUE;
  183. }
  184.  
  185.  
  186. //----------------------------------------------------------------------------
  187. //   Description:    Event monitor function.
  188. //    Parameters:    msg        Event code
  189. //                        pv1            Data pointer 1
  190. //                        pv2            Data pointer 2
  191. //       Returns:    Event code
  192. //----------------------------------------------------------------------------
  193. ZN_MSG FN_M ZI_CS_LIST::User(ZN_MSG msg, PVOID, PVOID pv2)
  194. {
  195.     switch (msg)
  196.         {
  197.         case ZN_MSG_INIT:
  198.             return msg;
  199.  
  200.         case ZN_MSG_TERMINATE:
  201.             return msg;
  202.  
  203.         case ZN_MSG_VLIST_INIT:
  204.             {
  205. static int aiTabstops[] = { 2, 6, 55, 62, 0, 0 };
  206.  
  207.             PZN_VLIST_INIT pzn_vlist_init = (PZN_VLIST_INIT)pv2;
  208.             pzn_vlist_init->lElems = lRecords;
  209.             pzn_vlist_init->fs = ZN_VLIST_SINGLE|ZN_VLIST_TITLE;
  210.             pzn_vlist_init->aiTabstops = aiTabstops;
  211.             }
  212.             return msg;
  213.  
  214.         case ZN_MSG_VLIST_TITLE:
  215.             {
  216.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  217.             pzn_vlist_elem->pszBuf = szFormat;
  218.             strcpy(szFormat, "\tST\tCity\tZIP");
  219.             }
  220.             return msg;
  221.         }
  222.     if (IsError())                                // Error condition
  223.         return msg;
  224.     switch (msg)
  225.         {
  226.         case ZN_MSG_VLIST_QUERY:
  227.             Query((PZN_VLIST_ELEM)pv2);
  228.             break;
  229.  
  230.         case ZN_MSG_VLIST_SELECT:
  231.             {
  232.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  233.             lCurrent = pzn_vlist_elem->lId;
  234.             }
  235.             // Fall through
  236.         case ZN_MSG_VLIST_CURRENT:
  237.             {
  238.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  239.             LONG lRec = pzn_vlist_elem->lId;
  240.             sprintf(szFormat, "City %ld of %ld", lRec + 1, lRecords);
  241.             SetHelp(szFormat);
  242.             }
  243.             break;
  244.  
  245.         case ZN_MSG_VLIST_DBL_CLK:
  246.             {
  247.             PZN_VLIST_ELEM pzn_vlist_elem = (PZN_VLIST_ELEM)pv2;
  248.             lCurrent = pzn_vlist_elem->lId;
  249.             }
  250.         case TB_DETAIL:
  251.             Detail();
  252.             break;
  253.  
  254.         case TB_SELECT:
  255.             Select();
  256.             break;
  257.  
  258.         case ZN_MSG_HELP:
  259.             return ZN_MSG_NO_HELP;
  260.  
  261.         case TB_CLOSE:
  262.             Close();
  263.             break;
  264.  
  265.         case TB_HELP:
  266.             NotDone();
  267.             break;
  268.         }
  269.     return msg;
  270. }
  271. //----------------------------------------------------------------------------
  272. //------------------------------- End of File --------------------------------
  273. //----------------------------------------------------------------------------
  274.